from minio import Minio

# 创建 Minio 客户端
client = Minio(
    endpoint="120.24.64.102:9000",
    access_key="root",
    secret_key="239489Cps",
    secure=False
)


def push2minio(file_path):
    # 上传文件
    bucket_name = "bucket"
    file_path = "apkfilter/"+file_path
    object_name = "file.txt"

    try:
        client.fput_object(
            bucket_name=bucket_name,
            object_name=object_name,
            file_path=file_path
        )
        print(f"Successfully uploaded {object_name} to {bucket_name}")
    except Exception as e:
        print(f"Error uploading file: {e}")


def download_file(bucket_name, object_name):
    # 下载文件
    client.fget_object("bucket", "example.txt", "example_downloaded.txt")

def get_file_list():
    # 列出存储桶中的文件
    objects = client.list_objects("bucket", recursive=True)

    fl=[]
    for obj in objects:
        fl.append({'name':obj.object_name,'size':obj.size,'last_modified':obj.last_modified})
    return fl

push2minio('2c.apk')